package TASK;
//http://docstore.mik.ua/orelly/java-ent/jnut/ch04_08.htm

public class Clock extends Thread {
	  java.text.DateFormat f =      // How to format the time for this locale
	  java.text.DateFormat.getTimeInstance(java.text.DateFormat.MEDIUM);
	  boolean keepRunning = true;
	  String told = f.format(new java.util.Date());

	  public Clock() {         // The constructor
	    //setDaemon(true);       // Daemon thread: interpreter can exit while it runs
	    this.start();               // This thread starts itself
	  }

	  public void run() {      // The body of the thread
		  System.out.println(keepRunning); 
	    while(keepRunning) {   // This thread runs until asked to stop
	      String time = f.format(new java.util.Date()); // Current time
	      System.out.println(time);                     // Print the time
	      
	      
	      
	      try { Thread.sleep(1000); }                   // Wait 1000 milliseconds
	      catch (InterruptedException e) {System.out.println(e.getMessage());}             // Ignore this exception 
	    }
	  }

	  // Ask the thread to stop running
	  public void pleaseStop() { keepRunning = false; }
	  
	  public static void main(String[] args) {
		 Clock a = new Clock();
	  }
	}